import utils from "../utils";
import Cookies from "js-cookie";
const TOKEN_STR = 'Authorization';

export default class Token {
    public Get(): any {
        const val = Cookies.get(TOKEN_STR);
        return utils.empty(val) ? '' : val;
    }
    /**
     * 
     * @param val token值
     * @param autoLogin 是否自动登录
     * @param expires token保存时间（秒）默认：604800
     */
    public Set(val = '', autoLogin: boolean = false, expires: number = 604800) {
        if (!utils.empty(val)) {
            console.log(new Date(new Date().setSeconds(expires)));
            if (autoLogin) {
                Cookies.set(TOKEN_STR, val, {
                    expires: new Date(new Date().setSeconds(expires)),
                });
            } else {
                Cookies.set(TOKEN_STR, val);
            }
        }
    }
    public Remove() {
        Cookies.remove(TOKEN_STR);
    }
}
